import React from 'react'

class Cos extends React.Component{
    state = {
        isShow:false,
        
    }
    toggle = () => {
        //类的方法默认不绑定this
        this.setState({
            isShow:!this.state.isShow
        })
    }
    showItem = (item,e) => {
        console.log(item)
        console.log(e)
    }
    render() {
        let {title,list} = this.props;
        return (
            <div>
                <h2 onClick={this.toggle}>{title}</h2>
                {
                    this.state.isShow && 
                    <ol>
                        {
                            list.map(item=>{
                                return <li onClick={(e) => {this.showItem(item,e)}}>{item}</li>
                            })
                        }
                    </ol>
                }
            </div>
        )
    }
}

export default Cos